import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import {Observable, BehaviorSubject} from "rxjs";
import {Params, ActivatedRoute} from "@angular/router";

import {HomepageService} from "@homepage/homepage.service";
import {UserAlbumFileVO, UserInfoVO} from "@interface/index";


@Component({
  selector: 'seed-viewer-album',
  templateUrl: './viewer.component.html',
  styleUrls: ['./viewer.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class ViewerAlbumComponent implements OnInit {

  public userId: UserInfoVO;
  public activeIndex: any;
  public rows: any;
  public _activeIndex: BehaviorSubject<any> = new BehaviorSubject<any>({});
  public gallery: Observable<UserAlbumFileVO[]>;

  constructor(public homepageService: HomepageService,
              public _activatedRoute: ActivatedRoute) {
    this.gallery = this.homepageService.gallery;
    this.activeIndex = this._activeIndex.asObservable();
  }

  ngOnInit() {
    this._activatedRoute.queryParams
      .subscribe((params: Params) => {
        this.rows = params['rows'];
        this.userId = params['userId'];
        this._activeIndex.next(params['index']);
        this.homepageService.getUserAlbum(params['userId'], 2, 1, 1, this.rows);
      });
  }
}
